import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_module_appaat/common/base/base_widget.dart';

/// create by MZP 2019-10-31 10:30
///
/// 通用的widget
///
///
/// ShapeBorder: 类的使用
///   - BeveledRectangleBorder 扁平或“斜角”角的矩形边框
///   - CircleBorder 可用空间内适合圆的边界
///   - StadiumBorder 半圆角矩形（StadiumBorder 翻译：像体育场形状的边框）

/// AppBar 附带右侧文字按钮
class AppBarWithRightBtn extends AppBar {
  final VoidCallback onPressed;
  final String btnText;
  final String titleText;

  AppBarWithRightBtn({this.onPressed, this.btnText = '', this.titleText = ''})
      : super(
          actions: <Widget>[
            FlatButton(
              textColor: Colors.white,
              child: Text(btnText),
              onPressed: btnText.isEmpty ? null : onPressed,
            )
          ],
          centerTitle: true,
          title: Text(titleText),
          backgroundColor: ResColors.app_main,
        );
}

class AppBarOnlyTitle extends AppBar {

  final String titleText;

  AppBarOnlyTitle(this.titleText)
      : super(
    centerTitle: true,
    title: Text(titleText,style: TextStyle(color: ResColors.white),),
    backgroundColor: ResColors.red_fe,
  );
}
/// 圆角按钮
class RoundedButton extends BaseStatelessWidget {
  final String text;
  final GestureTapCallback onTap; //点击事件
  final double width;

  RoundedButton({this.text = '确定', this.width = 100, this.onTap});

  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      color: ResColors.app_main,
      textColor: Colors.white,
      highlightColor: Theme.of(context).primaryColorLight,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
      // 阴影
      elevation: 2,
      // 按下时的阴影
      highlightElevation: 8,
      // 禁用时的阴影
      disabledElevation: 0,
      child: Container(alignment: Alignment.center, width: width, height: 35, child: Text(text)),
      onPressed: onTap,
    );
  }
}

/// 圆环按钮
class CircularButton extends BaseStatelessWidget {
  final String text;
  final GestureTapCallback onTap; //点击事件

  CircularButton({this.text = '确定', this.onTap});

  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      color: Colors.white,
      textColor: ResColors.app_main,
      highlightColor: Theme.of(context).primaryColorLight,
      shape: new StadiumBorder(
          side: new BorderSide(
        style: BorderStyle.solid,
        color: ResColors.app_main,
      )),
      // 阴影
      elevation: 2,
      // 按下时的阴影
      highlightElevation: 8,
      // 禁用时的阴影
      disabledElevation: 0,
      child: Text(text),
      onPressed: onTap,
    );
  }
}

/// 圆环按钮
class CircularDivButton extends BaseStatelessWidget {
  final String text;
  final GestureTapCallback onTap; //点击事件

  CircularDivButton({this.text = '确定', this.onTap});

  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      color: Colors.white,
      textColor: Theme.of(context).primaryColor,
      highlightColor: Theme.of(context).primaryColorLight,
      shape: new StadiumBorder(
          side: new BorderSide(
        style: BorderStyle.solid,
        color: Theme.of(context).primaryColor,
      )),
      // 阴影
      elevation: 2,
      // 按下时的阴影
      highlightElevation: 8,
      // 禁用时的阴影
      disabledElevation: 0,
      child: Text(text),
      onPressed: onTap,
    );
  }
}

class RefreshFooter extends ClassicalFooter {
  RefreshFooter()
      : super(
          loadText: "上拉加载",
          loadReadyText: "释放加载",
          loadingText: "正在加载…",
          loadedText: "加载完成",
          loadFailedText: "加载失败",
          noMoreText: "没有更多了",
          infoText: "更新时间为%T",
        );
}

class RefreshHeader extends ClassicalHeader {
  RefreshHeader()
      : super(
          refreshText: "下拉刷新",
          refreshReadyText: "松开刷新",
          refreshingText: "正在刷新中...",
          refreshedText: "刷新完成",
          refreshFailedText: "刷新失败",
          noMoreText: "没有更多了",
          infoText: "更新时间为%T",
        );
}

Decoration bottomGrayBorder = BoxDecoration(
  border: Border(bottom: BorderSide(width: 1, color: ResColors.gray)),
);

Decoration topGrayBorder = BoxDecoration(
  border: Border(top: BorderSide(width: 1, color: ResColors.gray)),
);

Decoration rightGrayBorder = BoxDecoration(
  border: Border(right: BorderSide(width: 1, color: ResColors.gray)),
);

Decoration leftGrayBorder = BoxDecoration(
  border: Border(left: BorderSide(width: 1, color: ResColors.gray)),
);

Decoration getDecoration(
    {double mLeft = 0, double mTop = 0, double mRight = 0, double mBottom = 0}) {
  return BoxDecoration(
    border: Border(
        left: BorderSide(width: mLeft, color: ResColors.gray),
        top: BorderSide(width: mTop, color: ResColors.gray),
        right: BorderSide(width: mRight, color: ResColors.gray),
        bottom: BorderSide(width: mBottom, color: ResColors.gray)),
  );
}

Image imgDefault = Image(
  image: AssetImage("images/default_image.png"),
  fit: BoxFit.fill,
);
